package com.dayly.tools;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import okio.BufferedSource;

public class ReNameTool {

    public static void main(String[] args) {

//        String name = "1.1_Kotlin语言的前世今生与课程目标(Av710705299,P1).mp4";
        File dir = new File("F:\\FFOutput");
        final File[] files = dir.listFiles();
        for (File file : files) {
            if(file.isDirectory())continue;
            final String name = file.getName();
            int startIndex = name.indexOf(".") + 1;
            int endIndex = name.indexOf("(");
            if (startIndex < endIndex && startIndex > 0) {
                String newName = name.substring(startIndex, endIndex) + name.substring(name.length() - 4);
//                System.out.println(/*file.getAbsolutePath() + " rename to " + */file.getParent() + newName);
                file.renameTo(new File(file.getParentFile(), newName));
            }
        }

/*
        Pattern pattern = Pattern.compile("\\.\\d+_\\w\\(");
        Matcher matcher = pattern.matcher(name);
        if (matcher.find()) {
            final String group = matcher.group();
            int start = matcher.start();
            int end = matcher.end();
            System.out.println(start + "," + end+" "+group);
        }
*/

    }
}
